<template>
	<view class="p-3">
		<view class="title">当日步数</view>
		<view class="todaybox flex align-center justify-center">
			{{num}}
		</view>
		<view class="title">历史步数（展示最近七天的步数）</view>
		<view class="charts-box">
			<qiun-data-charts type="line" :chartData="chartData" background="none" />
		</view>
	</view>
</template>

<script>
	// import qiunDataCharts from '../../components/qiun-data-charts/qiun-data-charts.vue';
	import moment from "moment"
	export default {
		// components:{qiunDataCharts},
		data() {
			return {
				num: 0,
				chartData: {
					"categories": [],
					"series": [{
						"name": "步数",
						"data": []
					}, ]
				}
			};
		},
		onLoad() {
			this.getNum();
			this.getWekData()
		},
		methods: {
			getNum() {
				let _this = this;

				let opts = {
					url: 'sport/step?imei='+uni.getStorageSync('imei'),
				};
				let param = {
					imei: uni.getStorageSync('imei')
				};
				_this.$http.httpDeveiceRequest(opts, param).then(
					res => {
						console.log(res.data);
						this.num = res.data.ReturnData.Steps
					},
					error => {
						console.log(error);
					}
				);
			},
			getWekData() {
				let _this = this;
				let opts = {
					url: 'sport/history?imei=' + uni.getStorageSync('imei') + '&startday=' + moment().subtract('days',
						6).format('YYYY-MM-DD') + '&endday=' + moment().format('YYYY-MM-DD'),
				};
				let param = {
					imei: uni.getStorageSync('imei'),
					startday: moment().subtract('days', 6).format('YYYY-MM-DD'),
					endday: moment().format('YYYY-MM-DD')

				};
				_this.$http.httpDeveiceRequest(opts, param).then(
					res => {
						if (res.data.ReturnData != "") {
							let xdata = [],
								ydata = [];
							res.data.ReturnData.forEach((item) => {
								xdata.push(item.Text);
								ydata.push(item.ID);
							});
							this.chartData.categories = xdata;
							this.chartData.series[0].data = ydata;
						}
					},
					error => {
						console.log(error);
					}
				);
			}
		}
	}
</script>

<style lang="scss">
	/* 请根据需求修改图表容器尺寸，如果父容器没有高度图表则会显示异常 */
	.charts-box {
		width: 100%;
		height: 300px;
	}

	.title {
		font-size: 30rpx;
		font-weight: bold;
		margin: 20rpx 0;
	}

	.todaybox {
		width: 350rpx;
		height: 350rpx;
		overflow: hidden;
		background: url(../../static/img/bsbg.png) no-repeat -30rpx -50rpx;
		background-size: 450rpx 450rpx;
		margin: 0 auto;
	}
</style>
